package com.demo1105;

import java.util.Scanner;

public class Q2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n]; // 使用long避免大数值溢出
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        // 若数组长度为1，只有一个子数组，权值为0
        if (n == 1) {
            System.out.println(0);
            return;
        }
        // 计算相邻元素差的绝对值数组diff
        int m = n - 1;
        long[] diff = new long[m];
        for (int i = 0; i < m; i++) {
            diff[i] = Math.abs(a[i + 1] - a[i]);
        }
        long total = 0;
        // 遍历diff数组的所有非空连续子数组，累加最大值
        for (int i = 0; i < m; i++) {
            long currentMax = diff[i];
            total += currentMax; // 子数组[i..i]的最大值
            // 扩展子数组到[i..j]，更新最大值并累加
            for (int j = i + 1; j < m; j++) {
                if (diff[j] > currentMax) {
                    currentMax = diff[j];
                }
                total += currentMax;
            }
        }
        System.out.println(total);
    }
}
